package com.android.common.network;

import android.annotation.SuppressLint;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import com.android.common.constant.Constant;

public class NetWorkConnectInfo {

    /**
     * 判断当前网络是否可用
     * @return boolean
     */
    @SuppressLint("MissingPermission")
    public static boolean isAvailable(){
        ConnectivityManager connectivityManager = (ConnectivityManager) Constant.GLOBAL_APPLICATION.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        return networkInfo != null && networkInfo.isAvailable();
    }

    /**
     * 获取网络连接管理类
     */
    @SuppressLint("MissingPermission")
    public static ConnectivityManager getConnectivityManager(){
        ConnectivityManager connectivityManager = (ConnectivityManager) Constant.GLOBAL_APPLICATION.getSystemService(Context.CONNECTIVITY_SERVICE);
        return connectivityManager;
    }
}
